<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\api\controller\v1\publics;

use app\Request;
use app\services\article\ArticleServices;

/**
 * 文章类
 * Class ArticleController
 * @package app\api\controller\publics
 */
class ArticleController
{
    protected $services;

    public function __construct(ArticleServices $services)
    {
        $this->services = $services;
    }

    /**
     * 获取列表
     * @return mixed
     */
    public function index(Request $request)
    {
        $page = request()->all('page') ?? 1;
        $limit = request()->all('limit') ?? 1000;
        $where = $request->getMore([
            ['title', ''],
            ['cid', 0],
            ['add_time_start',0],
            ['add_time_end',0],

        ]);
        $data = $this->services->getList($where, $page, $limit, 'id,cid,title,image_input');
        if($data['count'] > 0){
            foreach ($data['list'] as $key => $item){
                unset($data['list'][$key]['store_name']);
            }
        }
        return app('json')->success($data);
    }

    /**
     * 获取单个文章数据
     * @param int $id
     * @return mixed
     */
    public function read($id = 0)
    {
        if (!$id) return app('json')->fail(100100);
        $info = $this->services->read($id);
        return app('json')->success($info);
    }
}
